package com.study.java.jinjie.jihe.lianxi.liu;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Score {
    Map<Integer,Student> studentMap ;

    public Score(Map<Integer, Student> studentMap) {
        this.studentMap = studentMap;
    }

    public void printmap(){
        int l = studentMap.size();
        int i = 1 ;
        Set<Integer> sets  = studentMap.keySet();
        System.out.print("序号\t"+"  学号\t"+ "  姓名\t"+"成绩\n");
        System.out.println("--------------------------------");
        Iterator<Integer> iterator = sets.iterator();;
        while (iterator.hasNext()) {
            Student student = studentMap.get(iterator.next());
            System.out.println( i++ + "\t" + student.getNum() + "\t" + student.getName() + "   \t" + student.getChengJi());
            System.out.println("--------------------------------");
        }
    }

     public void pingJun (){
        float zong = 0f;
        int renShu = 0;
        float pingjun = 0f;
        Set<Integer> sets  = studentMap.keySet();
        Iterator<Integer> iterator = sets.iterator();
        while (iterator.hasNext()){
            Student student = studentMap.get(iterator.next());
            renShu++;
            zong = zong + student.getChengJi();
        }
        pingjun = zong/renShu;
        System.out.println("平均成绩:" + pingjun);
    }

    public void max(){
        int max = 0;
        String n = " ";
        Set<Integer> sets = studentMap.keySet();
        Iterator<Integer> iterator = sets.iterator();
        while (iterator.hasNext()){
            Student student = studentMap.get(iterator.next());
            if (max < student.getChengJi()){
                max = student.getChengJi();
                n = student.getName();
            }
        }
        System.out.println( "成绩最高学生为:" + n + "  成绩:" + max );
    }
}
